angular.module('News').factory('LoginService', ['$http', '$timeout', 'UserService',
  function ($http, $timeout, UserService) {
      return {
          present:false,
          timerRef:null,
          timeout:10000,

          isPresent:function () {
              return this.present;
          },

          killTimer:function(){
              $timeout.cancel(this.timerRef);
              this.timerRef = null;
          },

          logIn:function () {
              var auth = "Basic " + btoa(UserService.userName + ":" +
                  UserService.password);

              $http.defaults.headers.common.Authorization = auth;

              return $http({ method:'GET', url:UserService.hostName +
                  "/index.php/apps/news/api/v1-2/version" });
          }
      };
  }]);

